﻿using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using WPFYuanShenDrawingVisual.ViewModels;
using Window = System.Windows.Window;

namespace WPFYuanShenDrawingVisual.Views;


public partial class MainWindow : Window
{
    private MainViewModel mainViewModel;

    public MainWindow()
    {
        InitializeComponent();

        // 获取屏幕工作区的宽度和高度
        double screenWidth = SystemParameters.WorkArea.Width;
        double screenHeight = SystemParameters.WorkArea.Height;

        // 设置窗体位置为右下角
        this.Left = screenWidth - this.Width;
        this.Top = screenHeight - this.Height;

        mainViewModel = new MainViewModel();
        this.DataContext = mainViewModel;

        var timer = new DispatcherTimer();
        timer.Interval = TimeSpan.FromSeconds(10);
        timer.Tick += (sender, args) =>
        {
            var rand = new Random(DateTime.Now.Millisecond);
            int i = rand.Next(minValue: 0, maxValue: 13) * 6 + 1;

            mainViewModel.ImageSource = mainViewModel.Images[i].Source;
            imageblock.RenderSize = (int)imageblock.RenderSize.Width == 400 ? new Size(401, 360) : new Size(400, 360);

            mainViewModel.Weather = mainViewModel.GetWeather();
        };
        timer.Start();
    }

    protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
    {
        base.OnMouseLeftButtonDown(e);
        DragMove();
    }

    protected override void OnKeyDown(KeyEventArgs e)
    {
        base.OnKeyDown(e);
        if (e.Key == Key.Escape)
            Application.Current.Shutdown();
    }

}